package  newcoder_exp.justPractise;

import org.junit.Test;

public class NC18 {
    public class Solution {
        /* 
        旋转矩阵：N*N
         */
        public int[][] rotateMatrix1(int[][] mat, int n) {
            int l = 0, u = 0, r = n - 1, b = n - 1, t = n - 1;
            while (l <= r && u <= b) {
                for (int i = l; i < r; i++) {
                    int temp = mat[u][i];
                    mat[u][i] = mat[t - i][l];
                    mat[t - i][l] = mat[b][t - i];
                    mat[b][t - i] = mat[i][r];
                    mat[i][r] = temp;
                }
                l++;
                r--;
                u++;
                b--;
            }
            return mat;
        }

        public int[][] rotateMatrix(int[][] mat, int n) {
            //先按照对角线翻转
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    int temp = mat[i][j];
                    mat[i][j] = mat[j][i];
                    mat[j][i] = temp;
                }
            }

            //将每一列逆序一下
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n / 2; j++) {
                    int temp = mat[i][j];
                    mat[i][j] = mat[i][n - j - 1];
                    mat[i][n - j - 1] = temp;
                }
            }
            return mat;
        }

    }

    @Test
    public void test() {
        Solution s = new Solution();
        int[] nums = new int[]{};
        
    }
}
